import { Types, Document } from 'mongoose';
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { MotionCategory, Muscles, MuscleGroup, Tool } from 'src/types/motion';

@Schema({ collection: 'motions', validateBeforeSave: true, versionKey: false })
export class Motion extends Document {
  @Prop({
    type: String,
    required: true,
    maxlength: 20,
  })
  name: string;

  @Prop({
    type: Number,
    required: true,
    enum: MotionCategory,
  })
  category: MotionCategory;

  @Prop({ type: Number, enum: MuscleGroup, default: 0 })
  group?: MuscleGroup;

  @Prop({ type: [String] })
  mainPart?: Muscles[];

  @Prop({ type: [String] })
  minorPart?: Muscles[];

  @Prop({ type: String, default: '' })
  img?: string;

  @Prop({ type: Number, enum: Tool, default: 0 })
  tool?: Tool;

  @Prop({ type: String, default: '' })
  description?: string;

  @Prop({ type: Types.ObjectId, ref: 'User' })
  userId?: Types.ObjectId;

  @Prop({ type: Boolean, default: true })
  canHandle?: boolean;
}

export const MotionSchema = SchemaFactory.createForClass(Motion);
